package org.szy.plugin.gen.controller;

import com.mybatisflex.core.query.QueryWrapper;
import org.noear.solon.annotation.*;
import org.noear.solon.core.handle.ModelAndView;
import org.szy.core.common.controller.BaseController;
import org.szy.core.common.entity.R;
import org.szy.plugin.gen.entity.GenConfig;
import org.szy.plugin.gen.param.GenConfigQueryParam;
import org.szy.plugin.gen.service.GenConfigService;

import java.util.List;

/**
 * 生成配置 控制层。
 *
 * @author sunzhiyang
 * @since 2023-06-14
 */
@Controller
@Mapping("/gen/config")
public class GenConfigController extends BaseController<GenConfig> {

    private final String PATH_PREFIX = "gen/config/";
    @Inject
    private GenConfigService genConfigService;

    @Get
    @Mapping("/index/{basicId}")
    public ModelAndView index(String basicId) {
        ModelAndView view = new ModelAndView(PATH_PREFIX + "index");
        view.put("basicId", basicId);
        return view;
    }

    @Get
    @Mapping("/list")
    public R<?> list(GenConfigQueryParam param) {
        QueryWrapper qw = genConfigService.qwByQuery(param);
        List<GenConfig> list = genConfigService.list(qw);
        return R.data(list);
    }

    @Put
    @Mapping("/editBatch")
    public R<?> editBatch(List<GenConfig> genConfigList) {
        boolean save = genConfigService.editBatch(genConfigList);
        return R.bool(save);
    }

}
